<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Zhou Wenying
  Date: 2023/4/13
  Time: 18:48
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>后台书籍审核管理</title>
    <link rel="stylesheet" href="/static/css/admin_style.css">
    <link type="text/css" rel="stylesheet" href="/static/layui/css/layui.css">
    <style>
        .right h2 {
            margin: 10px 0;
        }

        .right li {
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
<div id="app">
    <header>
        <div style="float: left;"><img src="/static/image/loginbg.jpg" width="152px" height="55px"></div>
        <div style="float: right;"><i class="layui-icon  layui-anim layui-anim-rotate layui-anim-loop"
                                      style="font-size: 30px; color: rgb(150, 155, 170);"></i>&nbsp; &nbsp; &nbsp;
        </div>
    </header>
    <div id="" class="main">

        <jsp:include page="/page/admin_base_left.jsp"></jsp:include>

        <div class="right">
            <div class="layui-row">

                <div class="layui-col-md11">
                    <div class="layui-row grid-demo">
                        <div class="layui-col-md10">

                            <div class="layui-panel">
                               <%-- <span style="padding:15px 15px 5px ">书籍审核管理</span>--%>
                                   <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                                       <ul class="layui-tab-title">
                                           <li class="layui-this">全部书籍</li>
                                           <li>书籍审核</li>
                                           <li>条幅推荐</li>
                                          <%-- <li>新书推荐</li>
                                           <li>热销推荐</li>--%>
                                       </ul>
                                       <div class="layui-tab-content">
                                           <div class="layui-tab-item layui-show">
                                               <table class="layui-table">
                                               <colgroup>
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col >
                                               </colgroup>
                                               <thead>
                                               <tr>
                                                   <th>书籍名称</th>
                                                   <th>书籍封面</th>
                                                   <th>书籍原价</th>
                                                   <th>书籍甩手价</th>
                                                   <th>详细信息</th>
                                                   <th>操作</th>
                                               </tr>
                                               </thead>
                                               <tbody id="pageMain">
                                               <c:forEach items="${book1}" var="book">
                                                   <tr id="bookId_${book.bookId}">
                                                       <td>${book.bookName}</td>
                                                       <td><img src="/getImg?img=${book.bookImg}" width="80px"/></td>
                                                       <td>${book.bookMoney}</td>
                                                       <td>${book.bookOldMoney}</td>
                                                       <td><a href="/showBook?bookId=${book.bookId}&noShow=1">查看详情</a></td>
                                                       <td>
                                                           <div class="layui-btn-container">
                                                               <button type="button" onclick="addTf(${book.bookId})" class="layui-btn layui-btn-radius" >加入条幅</button>
                                                                   <%--<button >通过</button>
                                                                   <button onclick="check(${book.bookId},2)">拒绝</button>--%>
                                                           </div>
                                                       </td>
                                                   </tr>
                                               </c:forEach>
                                               </tbody>
                                           </table>
                                               <div id="pagePage"></div>
                                           </div>
                                           <div class="layui-tab-item">
                                               <table class="layui-table">
                                               <colgroup>
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col >
                                               </colgroup>
                                               <thead>
                                               <tr>
                                                   <th>书籍名称</th>
                                                   <th>书籍封面</th>
                                                   <th>书籍原价</th>
                                                   <th>书籍甩手价</th>
                                                   <th>详细信息</th>
                                                   <th>操作</th>
                                               </tr>
                                               </thead>
                                               <tbody id="pageMain1">
                                               <c:forEach items="${book2}" var="book">
                                                   <tr id="bookId_${book.bookId}">
                                                       <td>${book.bookName}</td>
                                                       <td><img src="/getImg?img=${book.bookImg}" width="80px"/></td>
                                                       <td>${book.bookMoney}</td>
                                                       <td>${book.bookOldMoney}</td>
                                                       <td><a href="/showBook?bookId=${book.bookId}&noShow=1">查看详情</a></td>
                                                       <td>
                                                           <div class="layui-btn-group">
                                                               <button type="button" onclick="check(${book.bookId},1)" class="layui-btn layui-btn-radius" >通过</button>
                                                               <button type="button" onclick="check(${book.bookId},2)" class="layui-btn layui-btn-danger layui-btn-radius" >拒绝</button>

                                                                   <%--<button class="layui-btn-container" >通过</button>
                                                                   <button onclick="check(${book.bookId},2)">拒绝</button>--%>
                                                           </div>
                                                       </td>
                                                   </tr>
                                               </c:forEach>
                                               </tbody>
                                           </table>
                                               <div id="pagePage1"></div>
                                           </div>
                                           <div class="layui-tab-item">
                                               <table class="layui-table">
                                               <colgroup>
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col width="200">
                                                   <col >
                                               </colgroup>
                                               <thead>
                                               <tr>
                                                   <th>书籍名称</th>
                                                   <th>书籍封面</th>
                                                   <th>书籍原价</th>
                                                   <th>书籍甩手价</th>
                                                   <th>详细信息</th>
                                                   <th>操作</th>
                                               </tr>
                                               </thead>
                                               <tbody id="pageMain2">
                                               <c:forEach items="${lbBook}" var="book">
                                                   <tr id="bookId_${book.bookId}">
                                                       <td>${book.bookName}</td>
                                                       <td><img src="/getImg?img=${book.bookImg}" width="80px"/></td>
                                                       <td>${book.bookMoney}</td>
                                                       <td>${book.bookOldMoney}</td>
                                                       <td><a href="/showBook?bookId=${book.bookId}"&noShow=1>查看详情</a></td>
                                                       <td>
                                                           <div class="layui-btn-container">
                                                               <button type="button" onclick="delTf(${book.bookId})" class="layui-btn layui-btn-danger layui-btn-radius" >移除条幅</button>
                                                                   <%--<button >通过</button>
                                                                   <button onclick="check(${book.bookId},2)">拒绝</button>--%>
                                                           </div>
                                                       </td>
                                                   </tr>
                                               </c:forEach>
                                               </tbody>
                                           </table>
                                               <div id="pagePage2"></div>
                                           </div>
                                       </div>
                                   </div>

                            </div>

                        </div>
                    </div>

                </div>
            </div>

        </div>
    </div>
</div>
</body>
</html>

<script src="/static/js/jquery-3.6.1.min.js"></script>
<script src="/static/layer/layer.js"></script>
<script src="/static/js/layui-page.js"></script>
<script src="/static/layui/layui.js"></script>

<script>
/*Layui框架的LayuiPage插件*/
    let layerPage = null;
    let layerPage1 = null;
    let layerPage2 = null;
    $(function () {
        layerPage = new LayuiPage("#pageMain","#pagePage",6,0);
        layerPage1 = new LayuiPage("#pageMain1","#pagePage1",6,0);
        layerPage2 = new LayuiPage("#pageMain2","#pagePage2",6,0);

    })

    function addTf(id) {
        $.ajax({
            url:"/admin/doAdminAddTf?bookId="+id,
            type: "get",
            dataType: "json",
            contentType: false,
            success:function (json) {
                console.log(json);
                //var obj = JSON.parse(data);
                if (json.ret == 'true'){
                    layer.msg(json.data);
                    var html = "";
                    /*layerPage.deleteItem("bookId_"+id);*/
                }else {
                    layer.msg(json.data);
                }
            },
            error:function (data) {

            }
        });

    }

    function check(id,check) {
        $.ajax({
            url:"/admin/doAdminBook?bookId="+id+"&check="+check,
            type:"get",
            dataType:"json",
            //data:json,
            contentType: false,
            success:function (json) {
                console.log(json);
                //var obj = JSON.parse(data);
                if (json.ret == 'true'){
                    layer.msg(json.data);
                    layerPage1.deleteItem("bookId_"+id);
                }else {
                    layer.msg(json.data);
                }
            },
            error:function (data) {

            }
        });
    }

function delTf(id) {
    $.ajax({
        url:"/admin/doAdminDelTf?bookId="+id,
        type: "get",
        dataType: "json",
        contentType: false,
        success:function (json) {
            console.log(json);
            //var obj = JSON.parse(data);
            if (json.ret == 'true'){
                layer.msg(json.data);
                layerPage.deleteItem("bookId_"+id);
            }else {
                layer.msg(json.data);
            }
        },
        error:function (data) {

        }
    });

}

/*    //注意：选项卡 依赖 element 模块，否则无法进行功能性操作（初始化layui tab组件）
    layui.use('element', function(){
        var element = layui.element;

        //初始化Tab组件
        element.init();
    });

    /!*layui.use('element', function(){
        var element = layui.element;

        //添加新的标签页
        element.tabAdd('myTab', {
            title: '新标签页',
            content: '这是新标签页的内容'
        });
    });*!/

    layui.use('element', function(){
        var element = layui.element;

        //切换到第二个标签页（myTab是标签页容器的ID，1表示要切换到的标签页的索引（从0开始）。）
        element.tabChange('myTab', 1);
    });*/

    layui.use('element', function(){
        var $ = layui.jquery
            ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块

        //触发事件
        var active = {
            tabAdd: function(){
                //新增一个Tab项
                element.tabAdd('demo', {
                    title: '新选项'+ (Math.random()*1000|0) //用于演示
                    ,content: '内容'+ (Math.random()*1000|0)
                    ,id: new Date().getTime() //实际使用一般是规定好的id，这里以时间戳模拟下
                })
            }
            ,tabDelete: function(othis){
                //删除指定Tab项
                element.tabDelete('demo', '44'); //删除：“商品管理”
                othis.addClass('layui-btn-disabled');
            }
            ,tabChange: function(){
                //切换到指定Tab项
                element.tabChange('demo', '22'); //切换到：用户管理
            }
        };

        $('.site-demo-active').on('click', function(){
            var othis = $(this), type = othis.data('type');
            active[type] ? active[type].call(this, othis) : '';
        });

        //Hash地址的定位
        var layid = location.hash.replace(/^#test=/, '');
        element.tabChange('test', layid);

        element.on('tab(test)', function(elem){
            location.hash = 'test='+ $(this).attr('lay-id');
        });

    });

</script>